﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace RMSM
{
    [Serializable()]
    public class BenhNhanBO : Csla.BusinessBase<BenhNhanBO>
    {
        #region Business Properties

        private int? _BenhNhanID = null;
        public int? BenhNhanID
        {
            get { return this._BenhNhanID; }
            set { this._BenhNhanID = value; PropertyHasChanged("BenhNhanID"); }
        }

        private int? _Status = 0;
        public int? Status
        {
            get { return this._Status; }
            set { this._Status = value; PropertyHasChanged("Status"); }
        }

        private string _SoVaoVien = null;
        public string SoVaoVien
        {
            get { return this._SoVaoVien; }
            set { this._SoVaoVien = value; PropertyHasChanged("SoVaoVien"); }
        }

        private string _SoLuuTru = null;
        public string SoLuuTru
        {
            get { return this._SoLuuTru; }
            set { this._SoLuuTru = value; PropertyHasChanged("SoLuuTru"); }
        }

        private string _MaBenhNhan = null;
        public string MaBenhNhan
        {
            get { return this._MaBenhNhan; }
            set { this._MaBenhNhan = value; PropertyHasChanged("MaBenhNhan"); }
        }

        private string _HoTen = null;
        public string HoTen
        {
            get { return this._HoTen; }
            set { this._HoTen = value; PropertyHasChanged("HoTen"); }
        }

        private DateTime? _NgaySinh = null;
        public DateTime? NgaySinh
        {
            get { return this._NgaySinh; }
            set { this._NgaySinh = value; PropertyHasChanged("NgaySinh"); }
        }

        private bool? _GTNu = false;
        public bool? GTNu
        {
            get { return this._GTNu; }
            set { this._GTNu = value; PropertyHasChanged("GTNu"); }
        }

        private int? _DanTocID = StaticUtil.GetDefaultValue(LoaiDanhMuc.DanToc);
        public int? DanTocID
        {
            get { return this._DanTocID; }
            set { this._DanTocID = value; PropertyHasChanged("DanTocID"); }
        }

        private string _QueQuan = null;
        public string QueQuan
        {
            get { return this._QueQuan; }
            set { this._QueQuan = value; PropertyHasChanged("QueQuan"); }
        }

        private string _MucAn = null;
        public string MucAn
        {
            get { return this._MucAn; }
            set { this._MucAn = value; PropertyHasChanged("MucAn"); }
        }

        private string _SoPhieu = null;
        public string SoPhieu
        {
            get { return this._SoPhieu; }
            set { this._SoPhieu = value; PropertyHasChanged("SoPhieu"); }
        }

        private DateTime? _NgayKham = DateTime.Now;
        public DateTime? NgayKham
        {
            get { return this._NgayKham; }
            set { this._NgayKham = value; PropertyHasChanged("NgayKham"); }
        }

        private int? _SttKham = 1;
        public int? SttKham
        {
            get { return this._SttKham; }
            set { this._SttKham = value; PropertyHasChanged("SttKham"); }
        }

        private string _NgheNghiep = null;
        public string NgheNghiep
        {
            get { return this._NgheNghiep; }
            set { this._NgheNghiep = value; PropertyHasChanged("NgheNghiep"); }
        }

        private int? _DonViID = null;
        public int? DonViID
        {
            get { return this._DonViID; }
            set { this._DonViID = value; PropertyHasChanged("DonViID"); }
        }

        private int? _QuanHamID = null;
        public int? QuanHamID
        {
            get { return this._QuanHamID; }
            set { this._QuanHamID = value; PropertyHasChanged("QuanHamID"); }
        }

        private int? _ChucVuID = null;
        public int? ChucVuID
        {
            get { return this._ChucVuID; }
            set { this._ChucVuID = value; PropertyHasChanged("ChucVuID"); }
        }

        private string _HomThu = null;
        public string HomThu
        {
            get { return this._HomThu; }
            set { this._HomThu = value; PropertyHasChanged("HomThu"); }
        }

        private string _DiaChiThuongThu = null;
        public string DiaChiThuongThu
        {
            get { return this._DiaChiThuongThu; }
            set { this._DiaChiThuongThu = value; PropertyHasChanged("DiaChiThuongThu"); }
        }

        private int? _DoiTuongID = null;
        public int? DoiTuongID
        {
            get { return this._DoiTuongID; }
            set { this._DoiTuongID = value; PropertyHasChanged("DoiTuongID"); }
        }

        private string _BaoTin = null;
        public string BaoTin
        {
            get { return this._BaoTin; }
            set { this._BaoTin = value; PropertyHasChanged("BaoTin"); }
        }

        private int? _ChuyenKhoaID = null;
        public int? ChuyenKhoaID
        {
            get { return this._ChuyenKhoaID; }
            set { this._ChuyenKhoaID = value; PropertyHasChanged("ChuyenKhoaID"); }
        }

        private int? _PhongKhamID = null;
        public int? PhongKhamID
        {
            get { return this._PhongKhamID; }
            set { this._PhongKhamID = value; PropertyHasChanged("PhongKhamID"); }
        }

        private double? _TienKham = 0;
        public double? TienKham
        {
            get { return this._TienKham; }
            set { this._TienKham = value; PropertyHasChanged("TienKham"); }
        }

        private int? _BHYTNoiDangKyID = null;
        public int? BHYTNoiDangKyID
        {
            get { return this._BHYTNoiDangKyID; }
            set { this._BHYTNoiDangKyID = value; PropertyHasChanged("BHYTNoiDangKyID"); }
        }

        private int? _BHYTLoaiBaoHiemID = null;
        public int? BHYTLoaiBaoHiemID
        {
            get { return this._BHYTLoaiBaoHiemID; }
            set { this._BHYTLoaiBaoHiemID = value; PropertyHasChanged("BHYTLoaiBaoHiemID"); }
        }

        private int? _BHYTDoiTuongID = null;
        public int? BHYTDoiTuongID
        {
            get { return this._BHYTDoiTuongID; }
            set { this._BHYTDoiTuongID = value; PropertyHasChanged("BHYTDoiTuongID"); }
        }

        private string _BHYTMaThe = null;
        public string BHYTMaThe
        {
            get { return this._BHYTMaThe; }
            set { this._BHYTMaThe = value; PropertyHasChanged("BHYTMaThe"); }
        }

        private DateTime? _BHYTTuNgay = null;
        public DateTime? BHYTTuNgay
        {
            get { return this._BHYTTuNgay; }
            set { this._BHYTTuNgay = value; PropertyHasChanged("BHYTTuNgay"); }
        }

        private DateTime? _BHYTDenNgay = null;
        public DateTime? BHYTDenNgay
        {
            get { return this._BHYTDenNgay; }
            set { this._BHYTDenNgay = value; PropertyHasChanged("BHYTDenNgay"); }
        }

        private string _HBLyDoVaoVien = null;
        public string HBLyDoVaoVien
        {
            get { return this._HBLyDoVaoVien; }
            set { this._HBLyDoVaoVien = value; PropertyHasChanged("HBLyDoVaoVien"); }
        }

        private int? _HBSoNgayBiBenh = null;
        public int? HBSoNgayBiBenh
        {
            get { return this._HBSoNgayBiBenh; }
            set { this._HBSoNgayBiBenh = value; PropertyHasChanged("HBSoNgayBiBenh"); }
        }

        private string _HBQuaTrinhBenhLy = null;
        public string HBQuaTrinhBenhLy
        {
            get { return this._HBQuaTrinhBenhLy; }
            set { this._HBQuaTrinhBenhLy = value; PropertyHasChanged("HBQuaTrinhBenhLy"); }
        }

        private string _HBTienSuBenhBanThan = null;
        public string HBTienSuBenhBanThan
        {
            get { return this._HBTienSuBenhBanThan; }
            set { this._HBTienSuBenhBanThan = value; PropertyHasChanged("HBTienSuBenhBanThan"); }
        }

        private bool? _HBDiUng = false;
        public bool? HBDiUng
        {
            get { return this._HBDiUng; }
            set { this._HBDiUng = value; PropertyHasChanged("HBDiUng"); }
        }

        private bool? _HBMaTuy = false;
        public bool? HBMaTuy
        {
            get { return this._HBMaTuy; }
            set { this._HBMaTuy = value; PropertyHasChanged("HBMaTuy"); }
        }

        private bool? _HBRuouBia = false;
        public bool? HBRuouBia
        {
            get { return this._HBRuouBia; }
            set { this._HBRuouBia = value; PropertyHasChanged("HBRuouBia"); }
        }

        private bool? _HBThuocLa = false;
        public bool? HBThuocLa
        {
            get { return this._HBThuocLa; }
            set { this._HBThuocLa = value; PropertyHasChanged("HBThuocLa"); }
        }

        private bool? _HBThuocLao = false;
        public bool? HBThuocLao
        {
            get { return this._HBThuocLao; }
            set { this._HBThuocLao = value; PropertyHasChanged("HBThuocLao"); }
        }

        private bool? _HBKhac = false;
        public bool? HBKhac
        {
            get { return this._HBKhac; }
            set { this._HBKhac = value; PropertyHasChanged("HBKhac"); }
        }

        private string _HBDiUngTG = null;
        public string HBDiUngTG
        {
            get { return this._HBDiUngTG; }
            set { this._HBDiUngTG = value; PropertyHasChanged("HBDiUngTG"); }
        }

        private string _HBMaTuyTG = null;
        public string HBMaTuyTG
        {
            get { return this._HBMaTuyTG; }
            set { this._HBMaTuyTG = value; PropertyHasChanged("HBMaTuyTG"); }
        }

        private string _HBRuouBiaTG = null;
        public string HBRuouBiaTG
        {
            get { return this._HBRuouBiaTG; }
            set { this._HBRuouBiaTG = value; PropertyHasChanged("HBRuouBiaTG"); }
        }

        private string _HBThuocLaTG = null;
        public string HBThuocLaTG
        {
            get { return this._HBThuocLaTG; }
            set { this._HBThuocLaTG = value; PropertyHasChanged("HBThuocLaTG"); }
        }

        private string _HBThuocLaoTG = null;
        public string HBThuocLaoTG
        {
            get { return this._HBThuocLaoTG; }
            set { this._HBThuocLaoTG = value; PropertyHasChanged("HBThuocLaoTG"); }
        }

        private string _HBKhacTG = null;
        public string HBKhacTG
        {
            get { return this._HBKhacTG; }
            set { this._HBKhacTG = value; PropertyHasChanged("HBKhacTG"); }
        }

        private string _HBTienSuBenhGiaDinh = null;
        public string HBTienSuBenhGiaDinh
        {
            get { return this._HBTienSuBenhGiaDinh; }
            set { this._HBTienSuBenhGiaDinh = value; PropertyHasChanged("HBTienSuBenhGiaDinh"); }
        }

        private string _KBToanThan = null;
        public string KBToanThan
        {
            get { return this._KBToanThan; }
            set { this._KBToanThan = value; PropertyHasChanged("KBToanThan"); }
        }

        private double? _KBMach = null;
        public double? KBMach
        {
            get { return this._KBMach; }
            set { this._KBMach = value; PropertyHasChanged("KBMach"); }
        }

        private double? _KBNhietDo = null;
        public double? KBNhietDo
        {
            get { return this._KBNhietDo; }
            set { this._KBNhietDo = value; PropertyHasChanged("KBNhietDo"); }
        }

        private double? _KBHuyetAp1 = null;
        public double? KBHuyetAp1
        {
            get { return this._KBHuyetAp1; }
            set { this._KBHuyetAp1 = value; PropertyHasChanged("KBHuyetAp1"); }
        }

        private double? _KBHuyetAp2 = null;
        public double? KBHuyetAp2
        {
            get { return this._KBHuyetAp2; }
            set { this._KBHuyetAp2 = value; PropertyHasChanged("KBHuyetAp2"); }
        }

        private double? _KBNhipTho = null;
        public double? KBNhipTho
        {
            get { return this._KBNhipTho; }
            set { this._KBNhipTho = value; PropertyHasChanged("KBNhipTho"); }
        }

        private double? _KBCanNang = null;
        public double? KBCanNang
        {
            get { return this._KBCanNang; }
            set { this._KBCanNang = value; PropertyHasChanged("KBCanNang"); }
        }

        private double? _KBChieuCao = null;
        public double? KBChieuCao
        {
            get { return this._KBChieuCao; }
            set { this._KBChieuCao = value; PropertyHasChanged("KBChieuCao"); }
        }

        private string _KBCacCoQuan = null;
        public string KBCacCoQuan
        {
            get { return this._KBCacCoQuan; }
            set { this._KBCacCoQuan = value; PropertyHasChanged("KBCacCoQuan"); }
        }

        private string _KBCacXetNghiemCLS = null;
        public string KBCacXetNghiemCLS
        {
            get { return this._KBCacXetNghiemCLS; }
            set { this._KBCacXetNghiemCLS = value; PropertyHasChanged("KBCacXetNghiemCLS"); }
        }

        private string _KBTomTatBenhAn = null;
        public string KBTomTatBenhAn
        {
            get { return this._KBTomTatBenhAn; }
            set { this._KBTomTatBenhAn = value; PropertyHasChanged("KBTomTatBenhAn"); }
        }

        private DateTime? _CDNgay = null;
        public DateTime? CDNgay
        {
            get { return this._CDNgay; }
            set { this._CDNgay = value; PropertyHasChanged("CDNgay"); }
        }

        private int? _CDBenhChinhID = null;
        public int? CDBenhChinhID
        {
            get { return this._CDBenhChinhID; }
            set { this._CDBenhChinhID = value; PropertyHasChanged("CDBenhChinhID"); }
        }

        private string _CDBenhKemTheoIDList = null;
        public string CDBenhKemTheoIDList
        {
            get { return this._CDBenhKemTheoIDList; }
            set { this._CDBenhKemTheoIDList = value; PropertyHasChanged("CDBenhKemTheoIDList"); }
        }

        private string _CDBienChungIDList = null;
        public string CDBienChungIDList
        {
            get { return this._CDBienChungIDList; }
            set { this._CDBienChungIDList = value; PropertyHasChanged("CDBienChungIDList"); }
        }

        private string _CDPhanBiet = null;
        public string CDPhanBiet
        {
            get { return this._CDPhanBiet; }
            set { this._CDPhanBiet = value; PropertyHasChanged("CDPhanBiet"); }
        }

        private string _KLTienLuong = null;
        public string KLTienLuong
        {
            get { return this._KLTienLuong; }
            set { this._KLTienLuong = value; PropertyHasChanged("KLTienLuong"); }
        }

        private string _KLHuongDieuTri = null;
        public string KLHuongDieuTri
        {
            get { return this._KLHuongDieuTri; }
            set { this._KLHuongDieuTri = value; PropertyHasChanged("KLHuongDieuTri"); }
        }

        private string _KLTaiKham = null;
        public string KLTaiKham
        {
            get { return this._KLTaiKham; }
            set { this._KLTaiKham = value; PropertyHasChanged("KLTaiKham"); }
        }

        private string _KLLoiDan = null;
        public string KLLoiDan
        {
            get { return this._KLLoiDan; }
            set { this._KLLoiDan = value; PropertyHasChanged("KLLoiDan"); }
        }

        private int? _KLKhoaID = null;
        public int? KLKhoaID
        {
            get { return this._KLKhoaID; }
            set { this._KLKhoaID = value; PropertyHasChanged("KLKhoaID"); }
        }

        private DateTime? _KLNgayVaoVien = null;
        public DateTime? KLNgayVaoVien
        {
            get { return this._KLNgayVaoVien; }
            set { this._KLNgayVaoVien = value; PropertyHasChanged("KLNgayVaoVien"); }
        }

        private int? _BuongID = null;
        public int? BuongID
        {
            get { return this._BuongID; }
            set { this._BuongID = value; PropertyHasChanged("BuongID"); }
        }

        private int? _GiuongID = null;
        public int? GiuongID
        {
            get { return this._GiuongID; }
            set { this._GiuongID = value; PropertyHasChanged("GiuongID"); }
        }

        private int? _UserCreated = Session.LoginID;
        public int? UserCreated
        {
            get { return this._UserCreated; }
            set { this._UserCreated = value; PropertyHasChanged("UserCreated"); }
        }

        private DateTime? _DateCreated = DateTime.MaxValue;
        public DateTime? DateCreated
        {
            get { return this._DateCreated; }
            set { this._DateCreated = value; PropertyHasChanged("DateCreated"); }
        }

        private int? _UserModify = null;
        public int? UserModify
        {
            get { return this._UserModify; }
            set { this._UserModify = value; PropertyHasChanged("UserModify"); }
        }

        private DateTime? _DateModify = null;
        public DateTime? DateModify
        {
            get { return this._DateModify; }
            set { this._DateModify = value; PropertyHasChanged("DateModify"); }
        }

        private bool? _Deleted = false;
        public bool? Deleted
        {
            get { return this._Deleted; }
            set { this._Deleted = value; PropertyHasChanged("Deleted"); }
        }

        private int? _STT0 = 0;
        public int? STT0
        {
            get { return _STT0; }
            set { _STT0 = value; }
        }

        protected override object GetIdValue()
        {
            return _BenhNhanID.Value;
        }
        #endregion Business Properties
        //==========================================================================

        #region Factory Methods
        public void SetIsNew()
        {
            MarkNew();
        }

        public void SetIsOld()
        {
            MarkOld();
        }

        public void SetIsDirty()
        {
            MarkDirty();
        }

        public void SetIsChild()
        {
            MarkAsChild();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }

        private static int newBenhNhanID = -1;
        private BenhNhanBO()
        {
            _BenhNhanID = newBenhNhanID--;
        }

        public BenhNhanBO(SqlDataReader dataReader)
        {
            MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public BenhNhanBO(SqlDataReader dataReader, bool isRoot)
        {
            if (!isRoot)
                MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public static BenhNhanBO NewRootBenhNhanBO()
        {
            return DataPortal.Create<BenhNhanBO>(new RootCriteria());
        }

        internal static BenhNhanBO NewChildBenhNhanBO()
        {
            return DataPortal.Create<BenhNhanBO>(new ChildCriteria());
        }

        public static BenhNhanBO GetRootBenhNhanBO(int _BenhNhanID)
        {
            return DataPortal.Fetch<BenhNhanBO>(new RootCriteria(_BenhNhanID));
        }

        public static BenhNhanBO GetRootBenhNhanBOByWhere(string where)
        {
            return DataPortal.Fetch<BenhNhanBO>(where);
        }

        internal static BenhNhanBO GetChildBenhNhanBO(SqlDataReader dataReader)
        {
            return new BenhNhanBO(dataReader);
        }

        public static void DeleteBenhNhanBO(int _BenhNhanID)
        {
            DataPortal.Delete(new RootCriteria(_BenhNhanID));
        }

        public static void DeleteBenhNhanBO(int _BenhNhanID, bool directDelete)
        {
            DataPortal.Delete(new RootCriteria(_BenhNhanID, directDelete));
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        public class RootCriteria
        {
            public int BenhNhanID;
            public bool directDelete = false;
            public RootCriteria(int _BenhNhanID)
            {
                this.BenhNhanID = _BenhNhanID;
                this.directDelete = false;
            }

            public RootCriteria(int _BenhNhanID, bool directDelete)
            {
                this.BenhNhanID = _BenhNhanID;
                this.directDelete = directDelete;
            }

            public RootCriteria() { }
        }

        [Serializable()]
        public class ChildCriteria
        {
            public int BenhNhanID;
            public bool directDelete = false;
            public ChildCriteria(int _BenhNhanID)
            {
                this.BenhNhanID = _BenhNhanID;
                this.directDelete = false;
            }

            public ChildCriteria(int _BenhNhanID, bool directDelete)
            {
                this.BenhNhanID = _BenhNhanID;
                this.directDelete = directDelete;
            }

            public ChildCriteria() { }
        }
        #endregion Criteria
        //==========================================================================

        #region Create
        [RunLocal]
        private void DataPortal_Create(RootCriteria criteria)
        {
        }

        private void DataPortal_Create(ChildCriteria criteria)
        {
            MarkAsChild();
            ValidationRules.CheckRules();
        }

        #endregion Create
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Fetch(RootCriteria criteria)
        {
            this.Execute_Fetch(criteria);
        }

        protected void DataPortal_Fetch(string where)
        {
            this.Execute_Fetch(where);
        }

        protected void Execute_Fetch(RootCriteria criteria)
        {
            this.This_Fetch(criteria);
        }

        protected void Execute_Fetch(string where)
        {
            this.This_Fetch(where);
        }

        private void This_Fetch(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BenhNhanBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, "[BenhNhanID] = " + criteria.BenhNhanID);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void This_Fetch(string where)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BenhNhanBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, where);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void Fetch(SqlDataReader dataReader)
        {
            if (!(dataReader["BenhNhanID"] is DBNull))
                this._BenhNhanID = (int)dataReader["BenhNhanID"];
            if (!(dataReader["Status"] is DBNull))
                this._Status = (int)dataReader["Status"];
            if (!(dataReader["SoVaoVien"] is DBNull))
                this._SoVaoVien = (string)dataReader["SoVaoVien"];
            if (!(dataReader["SoLuuTru"] is DBNull))
                this._SoLuuTru = (string)dataReader["SoLuuTru"];
            if (!(dataReader["MaBenhNhan"] is DBNull))
                this._MaBenhNhan = (string)dataReader["MaBenhNhan"];
            if (!(dataReader["HoTen"] is DBNull))
                this._HoTen = (string)dataReader["HoTen"];
            if (!(dataReader["NgaySinh"] is DBNull))
                this._NgaySinh = (DateTime)dataReader["NgaySinh"];
            if (!(dataReader["GTNu"] is DBNull))
                this._GTNu = (bool)dataReader["GTNu"];
            if (!(dataReader["DanTocID"] is DBNull))
                this._DanTocID = (int)dataReader["DanTocID"];
            if (!(dataReader["QueQuan"] is DBNull))
                this._QueQuan = (string)dataReader["QueQuan"];
            if (!(dataReader["MucAn"] is DBNull))
                this._MucAn = (string)dataReader["MucAn"];
            if (!(dataReader["SoPhieu"] is DBNull))
                this._SoPhieu = (string)dataReader["SoPhieu"];
            if (!(dataReader["NgayKham"] is DBNull))
                this._NgayKham = (DateTime)dataReader["NgayKham"];
            if (!(dataReader["SttKham"] is DBNull))
                this._SttKham = (int)dataReader["SttKham"];
            if (!(dataReader["NgheNghiep"] is DBNull))
                this._NgheNghiep = (string)dataReader["NgheNghiep"];
            if (!(dataReader["DonViID"] is DBNull))
                this._DonViID = (int)dataReader["DonViID"];
            if (!(dataReader["QuanHamID"] is DBNull))
                this._QuanHamID = (int)dataReader["QuanHamID"];
            if (!(dataReader["ChucVuID"] is DBNull))
                this._ChucVuID = (int)dataReader["ChucVuID"];
            if (!(dataReader["HomThu"] is DBNull))
                this._HomThu = (string)dataReader["HomThu"];
            if (!(dataReader["DiaChiThuongThu"] is DBNull))
                this._DiaChiThuongThu = (string)dataReader["DiaChiThuongThu"];
            if (!(dataReader["DoiTuongID"] is DBNull))
                this._DoiTuongID = (int)dataReader["DoiTuongID"];
            if (!(dataReader["BaoTin"] is DBNull))
                this._BaoTin = (string)dataReader["BaoTin"];
            if (!(dataReader["ChuyenKhoaID"] is DBNull))
                this._ChuyenKhoaID = (int)dataReader["ChuyenKhoaID"];
            if (!(dataReader["PhongKhamID"] is DBNull))
                this._PhongKhamID = (int)dataReader["PhongKhamID"];
            if (!(dataReader["TienKham"] is DBNull))
                this._TienKham = (double)dataReader["TienKham"];
            if (!(dataReader["BHYTNoiDangKyID"] is DBNull))
                this._BHYTNoiDangKyID = (int)dataReader["BHYTNoiDangKyID"];
            if (!(dataReader["BHYTLoaiBaoHiemID"] is DBNull))
                this._BHYTLoaiBaoHiemID = (int)dataReader["BHYTLoaiBaoHiemID"];
            if (!(dataReader["BHYTDoiTuongID"] is DBNull))
                this._BHYTDoiTuongID = (int)dataReader["BHYTDoiTuongID"];
            if (!(dataReader["BHYTMaThe"] is DBNull))
                this._BHYTMaThe = (string)dataReader["BHYTMaThe"];
            if (!(dataReader["BHYTTuNgay"] is DBNull))
                this._BHYTTuNgay = (DateTime)dataReader["BHYTTuNgay"];
            if (!(dataReader["BHYTDenNgay"] is DBNull))
                this._BHYTDenNgay = (DateTime)dataReader["BHYTDenNgay"];
            if (!(dataReader["HBLyDoVaoVien"] is DBNull))
                this._HBLyDoVaoVien = (string)dataReader["HBLyDoVaoVien"];
            if (!(dataReader["HBSoNgayBiBenh"] is DBNull))
                this._HBSoNgayBiBenh = (int)dataReader["HBSoNgayBiBenh"];
            if (!(dataReader["HBQuaTrinhBenhLy"] is DBNull))
                this._HBQuaTrinhBenhLy = (string)dataReader["HBQuaTrinhBenhLy"];
            if (!(dataReader["HBTienSuBenhBanThan"] is DBNull))
                this._HBTienSuBenhBanThan = (string)dataReader["HBTienSuBenhBanThan"];
            if (!(dataReader["HBDiUng"] is DBNull))
                this._HBDiUng = (bool)dataReader["HBDiUng"];
            if (!(dataReader["HBMaTuy"] is DBNull))
                this._HBMaTuy = (bool)dataReader["HBMaTuy"];
            if (!(dataReader["HBRuouBia"] is DBNull))
                this._HBRuouBia = (bool)dataReader["HBRuouBia"];
            if (!(dataReader["HBThuocLa"] is DBNull))
                this._HBThuocLa = (bool)dataReader["HBThuocLa"];
            if (!(dataReader["HBThuocLao"] is DBNull))
                this._HBThuocLao = (bool)dataReader["HBThuocLao"];
            if (!(dataReader["HBKhac"] is DBNull))
                this._HBKhac = (bool)dataReader["HBKhac"];
            if (!(dataReader["HBDiUngTG"] is DBNull))
                this._HBDiUngTG = (string)dataReader["HBDiUngTG"];
            if (!(dataReader["HBMaTuyTG"] is DBNull))
                this._HBMaTuyTG = (string)dataReader["HBMaTuyTG"];
            if (!(dataReader["HBRuouBiaTG"] is DBNull))
                this._HBRuouBiaTG = (string)dataReader["HBRuouBiaTG"];
            if (!(dataReader["HBThuocLaTG"] is DBNull))
                this._HBThuocLaTG = (string)dataReader["HBThuocLaTG"];
            if (!(dataReader["HBThuocLaoTG"] is DBNull))
                this._HBThuocLaoTG = (string)dataReader["HBThuocLaoTG"];
            if (!(dataReader["HBKhacTG"] is DBNull))
                this._HBKhacTG = (string)dataReader["HBKhacTG"];
            if (!(dataReader["HBTienSuBenhGiaDinh"] is DBNull))
                this._HBTienSuBenhGiaDinh = (string)dataReader["HBTienSuBenhGiaDinh"];
            if (!(dataReader["KBToanThan"] is DBNull))
                this._KBToanThan = (string)dataReader["KBToanThan"];
            if (!(dataReader["KBMach"] is DBNull))
                this._KBMach = (double)dataReader["KBMach"];
            if (!(dataReader["KBNhietDo"] is DBNull))
                this._KBNhietDo = (double)dataReader["KBNhietDo"];
            if (!(dataReader["KBHuyetAp1"] is DBNull))
                this._KBHuyetAp1 = (double)dataReader["KBHuyetAp1"];
            if (!(dataReader["KBHuyetAp2"] is DBNull))
                this._KBHuyetAp2 = (double)dataReader["KBHuyetAp2"];
            if (!(dataReader["KBNhipTho"] is DBNull))
                this._KBNhipTho = (double)dataReader["KBNhipTho"];
            if (!(dataReader["KBCanNang"] is DBNull))
                this._KBCanNang = (double)dataReader["KBCanNang"];
            if (!(dataReader["KBChieuCao"] is DBNull))
                this._KBChieuCao = (double)dataReader["KBChieuCao"];
            if (!(dataReader["KBCacCoQuan"] is DBNull))
                this._KBCacCoQuan = (string)dataReader["KBCacCoQuan"];
            if (!(dataReader["KBCacXetNghiemCLS"] is DBNull))
                this._KBCacXetNghiemCLS = (string)dataReader["KBCacXetNghiemCLS"];
            if (!(dataReader["KBTomTatBenhAn"] is DBNull))
                this._KBTomTatBenhAn = (string)dataReader["KBTomTatBenhAn"];
            if (!(dataReader["CDNgay"] is DBNull))
                this._CDNgay = (DateTime)dataReader["CDNgay"];
            if (!(dataReader["CDBenhChinhID"] is DBNull))
                this._CDBenhChinhID = (int)dataReader["CDBenhChinhID"];
            if (!(dataReader["CDBenhKemTheoIDList"] is DBNull))
                this._CDBenhKemTheoIDList = (string)dataReader["CDBenhKemTheoIDList"];
            if (!(dataReader["CDBienChungIDList"] is DBNull))
                this._CDBienChungIDList = (string)dataReader["CDBienChungIDList"];
            if (!(dataReader["CDPhanBiet"] is DBNull))
                this._CDPhanBiet = (string)dataReader["CDPhanBiet"];
            if (!(dataReader["KLTienLuong"] is DBNull))
                this._KLTienLuong = (string)dataReader["KLTienLuong"];
            if (!(dataReader["KLHuongDieuTri"] is DBNull))
                this._KLHuongDieuTri = (string)dataReader["KLHuongDieuTri"];
            if (!(dataReader["KLTaiKham"] is DBNull))
                this._KLTaiKham = (string)dataReader["KLTaiKham"];
            if (!(dataReader["KLLoiDan"] is DBNull))
                this._KLLoiDan = (string)dataReader["KLLoiDan"];
            if (!(dataReader["KLKhoaID"] is DBNull))
                this._KLKhoaID = (int)dataReader["KLKhoaID"];
            if (!(dataReader["KLNgayVaoVien"] is DBNull))
                this._KLNgayVaoVien = (DateTime)dataReader["KLNgayVaoVien"];
            if (!(dataReader["BuongID"] is DBNull))
                this._BuongID = (int)dataReader["BuongID"];
            if (!(dataReader["GiuongID"] is DBNull))
                this._GiuongID = (int)dataReader["GiuongID"];
            if (!(dataReader["UserCreated"] is DBNull))
                this._UserCreated = (int)dataReader["UserCreated"];
            if (!(dataReader["DateCreated"] is DBNull))
                this._DateCreated = (DateTime)dataReader["DateCreated"];
            if (!(dataReader["UserModify"] is DBNull))
                this._UserModify = (int)dataReader["UserModify"];
            if (!(dataReader["DateModify"] is DBNull))
                this._DateModify = (DateTime)dataReader["DateModify"];
            if (!(dataReader["Deleted"] is DBNull))
                this._Deleted = (bool)dataReader["Deleted"];

        }
        #endregion Fetch
        //==========================================================================

        #region Insert
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            this.Execute_Insert();
        }

        protected void Execute_Insert()
        {
            this.This_Insert();
        }

        private void This_Insert()
        {
            this._UserCreated = Session.LoginID;
            this._DateCreated = DateTime.MaxValue;
            this._UserModify = null;
            this._DateModify = null;
            this._Deleted = false;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BenhNhanBO_InsertBO");
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@SoVaoVien", SqlDbType.NVarChar, this._SoVaoVien);
            db.AddInParameter(cmd, "@SoLuuTru", SqlDbType.NVarChar, this._SoLuuTru);
            db.AddInParameter(cmd, "@MaBenhNhan", SqlDbType.NVarChar, this._MaBenhNhan);
            db.AddInParameter(cmd, "@HoTen", SqlDbType.NVarChar, this._HoTen);
            db.AddInParameter(cmd, "@NgaySinh", SqlDbType.DateTime, this._NgaySinh);
            db.AddInParameter(cmd, "@GTNu", SqlDbType.Bit, this._GTNu);
            db.AddInParameter(cmd, "@DanTocID", SqlDbType.Int, this._DanTocID);
            db.AddInParameter(cmd, "@QueQuan", SqlDbType.NVarChar, this._QueQuan);
            db.AddInParameter(cmd, "@MucAn", SqlDbType.NVarChar, this._MucAn);
            db.AddInParameter(cmd, "@SoPhieu", SqlDbType.NVarChar, this._SoPhieu);
            db.AddInParameter(cmd, "@NgayKham", SqlDbType.DateTime, this._NgayKham);
            db.AddInParameter(cmd, "@SttKham", SqlDbType.Int, this._SttKham);
            db.AddInParameter(cmd, "@NgheNghiep", SqlDbType.NVarChar, this._NgheNghiep);
            db.AddInParameter(cmd, "@DonViID", SqlDbType.Int, this._DonViID);
            db.AddInParameter(cmd, "@QuanHamID", SqlDbType.Int, this._QuanHamID);
            db.AddInParameter(cmd, "@ChucVuID", SqlDbType.Int, this._ChucVuID);
            db.AddInParameter(cmd, "@HomThu", SqlDbType.NVarChar, this._HomThu);
            db.AddInParameter(cmd, "@DiaChiThuongThu", SqlDbType.NVarChar, this._DiaChiThuongThu);
            db.AddInParameter(cmd, "@DoiTuongID", SqlDbType.Int, this._DoiTuongID);
            db.AddInParameter(cmd, "@BaoTin", SqlDbType.NVarChar, this._BaoTin);
            db.AddInParameter(cmd, "@ChuyenKhoaID", SqlDbType.Int, this._ChuyenKhoaID);
            db.AddInParameter(cmd, "@PhongKhamID", SqlDbType.Int, this._PhongKhamID);
            db.AddInParameter(cmd, "@TienKham", SqlDbType.Float, this._TienKham);
            db.AddInParameter(cmd, "@BHYTNoiDangKyID", SqlDbType.Int, this._BHYTNoiDangKyID);
            db.AddInParameter(cmd, "@BHYTLoaiBaoHiemID", SqlDbType.Int, this._BHYTLoaiBaoHiemID);
            db.AddInParameter(cmd, "@BHYTDoiTuongID", SqlDbType.Int, this._BHYTDoiTuongID);
            db.AddInParameter(cmd, "@BHYTMaThe", SqlDbType.NVarChar, this._BHYTMaThe);
            db.AddInParameter(cmd, "@BHYTTuNgay", SqlDbType.DateTime, this._BHYTTuNgay);
            db.AddInParameter(cmd, "@BHYTDenNgay", SqlDbType.DateTime, this._BHYTDenNgay);
            db.AddInParameter(cmd, "@HBLyDoVaoVien", SqlDbType.NVarChar, this._HBLyDoVaoVien);
            db.AddInParameter(cmd, "@HBSoNgayBiBenh", SqlDbType.Int, this._HBSoNgayBiBenh);
            db.AddInParameter(cmd, "@HBQuaTrinhBenhLy", SqlDbType.NVarChar, this._HBQuaTrinhBenhLy);
            db.AddInParameter(cmd, "@HBTienSuBenhBanThan", SqlDbType.NVarChar, this._HBTienSuBenhBanThan);
            db.AddInParameter(cmd, "@HBDiUng", SqlDbType.Bit, this._HBDiUng);
            db.AddInParameter(cmd, "@HBMaTuy", SqlDbType.Bit, this._HBMaTuy);
            db.AddInParameter(cmd, "@HBRuouBia", SqlDbType.Bit, this._HBRuouBia);
            db.AddInParameter(cmd, "@HBThuocLa", SqlDbType.Bit, this._HBThuocLa);
            db.AddInParameter(cmd, "@HBThuocLao", SqlDbType.Bit, this._HBThuocLao);
            db.AddInParameter(cmd, "@HBKhac", SqlDbType.Bit, this._HBKhac);
            db.AddInParameter(cmd, "@HBDiUngTG", SqlDbType.NVarChar, this._HBDiUngTG);
            db.AddInParameter(cmd, "@HBMaTuyTG", SqlDbType.NVarChar, this._HBMaTuyTG);
            db.AddInParameter(cmd, "@HBRuouBiaTG", SqlDbType.NVarChar, this._HBRuouBiaTG);
            db.AddInParameter(cmd, "@HBThuocLaTG", SqlDbType.NVarChar, this._HBThuocLaTG);
            db.AddInParameter(cmd, "@HBThuocLaoTG", SqlDbType.NVarChar, this._HBThuocLaoTG);
            db.AddInParameter(cmd, "@HBKhacTG", SqlDbType.NVarChar, this._HBKhacTG);
            db.AddInParameter(cmd, "@HBTienSuBenhGiaDinh", SqlDbType.NVarChar, this._HBTienSuBenhGiaDinh);
            db.AddInParameter(cmd, "@KBToanThan", SqlDbType.NVarChar, this._KBToanThan);
            db.AddInParameter(cmd, "@KBMach", SqlDbType.Float, this._KBMach);
            db.AddInParameter(cmd, "@KBNhietDo", SqlDbType.Float, this._KBNhietDo);
            db.AddInParameter(cmd, "@KBHuyetAp1", SqlDbType.Float, this._KBHuyetAp1);
            db.AddInParameter(cmd, "@KBHuyetAp2", SqlDbType.Float, this._KBHuyetAp2);
            db.AddInParameter(cmd, "@KBNhipTho", SqlDbType.Float, this._KBNhipTho);
            db.AddInParameter(cmd, "@KBCanNang", SqlDbType.Float, this._KBCanNang);
            db.AddInParameter(cmd, "@KBChieuCao", SqlDbType.Float, this._KBChieuCao);
            db.AddInParameter(cmd, "@KBCacCoQuan", SqlDbType.NVarChar, this._KBCacCoQuan);
            db.AddInParameter(cmd, "@KBCacXetNghiemCLS", SqlDbType.NVarChar, this._KBCacXetNghiemCLS);
            db.AddInParameter(cmd, "@KBTomTatBenhAn", SqlDbType.NVarChar, this._KBTomTatBenhAn);
            db.AddInParameter(cmd, "@CDNgay", SqlDbType.DateTime, this._CDNgay);
            db.AddInParameter(cmd, "@CDBenhChinhID", SqlDbType.Int, this._CDBenhChinhID);
            db.AddInParameter(cmd, "@CDBenhKemTheoIDList", SqlDbType.VarChar, this._CDBenhKemTheoIDList);
            db.AddInParameter(cmd, "@CDBienChungIDList", SqlDbType.VarChar, this._CDBienChungIDList);
            db.AddInParameter(cmd, "@CDPhanBiet", SqlDbType.NVarChar, this._CDPhanBiet);
            db.AddInParameter(cmd, "@KLTienLuong", SqlDbType.NChar, this._KLTienLuong);
            db.AddInParameter(cmd, "@KLHuongDieuTri", SqlDbType.NChar, this._KLHuongDieuTri);
            db.AddInParameter(cmd, "@KLTaiKham", SqlDbType.NVarChar, this._KLTaiKham);
            db.AddInParameter(cmd, "@KLLoiDan", SqlDbType.NVarChar, this._KLLoiDan);
            db.AddInParameter(cmd, "@KLKhoaID", SqlDbType.Int, this._KLKhoaID);
            db.AddInParameter(cmd, "@KLNgayVaoVien", SqlDbType.DateTime, this._KLNgayVaoVien);
            db.AddInParameter(cmd, "@BuongID", SqlDbType.Int, this._BuongID);
            db.AddInParameter(cmd, "@GiuongID", SqlDbType.Int, this._GiuongID);
            db.AddInParameter(cmd, "@UserCreated", SqlDbType.Int, this._UserCreated);
            db.AddOutParameter(cmd, "@NewBenhNhanID", SqlDbType.Int, 10);
            db.AddOutParameter(cmd, "@NewDateCreated", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);
            this._BenhNhanID = (int)cmd.Parameters["@NewBenhNhanID"].Value;
            this._DateCreated = (DateTime)cmd.Parameters["@NewDateCreated"].Value;
        }
        #endregion Insert
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            this.Execute_Update();
        }

        protected void Execute_Update()
        {
            this.This_Update();
        }

        private void This_Update()
        {
            this._UserModify = Session.LoginID;
            this._DateModify = DateTime.Now;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BenhNhanBO_UpdateBO");
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, this._BenhNhanID);
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@SoVaoVien", SqlDbType.NVarChar, this._SoVaoVien);
            db.AddInParameter(cmd, "@SoLuuTru", SqlDbType.NVarChar, this._SoLuuTru);
            db.AddInParameter(cmd, "@MaBenhNhan", SqlDbType.NVarChar, this._MaBenhNhan);
            db.AddInParameter(cmd, "@HoTen", SqlDbType.NVarChar, this._HoTen);
            db.AddInParameter(cmd, "@NgaySinh", SqlDbType.DateTime, this._NgaySinh);
            db.AddInParameter(cmd, "@GTNu", SqlDbType.Bit, this._GTNu);
            db.AddInParameter(cmd, "@DanTocID", SqlDbType.Int, this._DanTocID);
            db.AddInParameter(cmd, "@QueQuan", SqlDbType.NVarChar, this._QueQuan);
            db.AddInParameter(cmd, "@MucAn", SqlDbType.NVarChar, this._MucAn);
            db.AddInParameter(cmd, "@SoPhieu", SqlDbType.NVarChar, this._SoPhieu);
            db.AddInParameter(cmd, "@NgayKham", SqlDbType.DateTime, this._NgayKham);
            db.AddInParameter(cmd, "@SttKham", SqlDbType.Int, this._SttKham);
            db.AddInParameter(cmd, "@NgheNghiep", SqlDbType.NVarChar, this._NgheNghiep);
            db.AddInParameter(cmd, "@DonViID", SqlDbType.Int, this._DonViID);
            db.AddInParameter(cmd, "@QuanHamID", SqlDbType.Int, this._QuanHamID);
            db.AddInParameter(cmd, "@ChucVuID", SqlDbType.Int, this._ChucVuID);
            db.AddInParameter(cmd, "@HomThu", SqlDbType.NVarChar, this._HomThu);
            db.AddInParameter(cmd, "@DiaChiThuongThu", SqlDbType.NVarChar, this._DiaChiThuongThu);
            db.AddInParameter(cmd, "@DoiTuongID", SqlDbType.Int, this._DoiTuongID);
            db.AddInParameter(cmd, "@BaoTin", SqlDbType.NVarChar, this._BaoTin);
            db.AddInParameter(cmd, "@ChuyenKhoaID", SqlDbType.Int, this._ChuyenKhoaID);
            db.AddInParameter(cmd, "@PhongKhamID", SqlDbType.Int, this._PhongKhamID);
            db.AddInParameter(cmd, "@TienKham", SqlDbType.Float, this._TienKham);
            db.AddInParameter(cmd, "@BHYTNoiDangKyID", SqlDbType.Int, this._BHYTNoiDangKyID);
            db.AddInParameter(cmd, "@BHYTLoaiBaoHiemID", SqlDbType.Int, this._BHYTLoaiBaoHiemID);
            db.AddInParameter(cmd, "@BHYTDoiTuongID", SqlDbType.Int, this._BHYTDoiTuongID);
            db.AddInParameter(cmd, "@BHYTMaThe", SqlDbType.NVarChar, this._BHYTMaThe);
            db.AddInParameter(cmd, "@BHYTTuNgay", SqlDbType.DateTime, this._BHYTTuNgay);
            db.AddInParameter(cmd, "@BHYTDenNgay", SqlDbType.DateTime, this._BHYTDenNgay);
            db.AddInParameter(cmd, "@HBLyDoVaoVien", SqlDbType.NVarChar, this._HBLyDoVaoVien);
            db.AddInParameter(cmd, "@HBSoNgayBiBenh", SqlDbType.Int, this._HBSoNgayBiBenh);
            db.AddInParameter(cmd, "@HBQuaTrinhBenhLy", SqlDbType.NVarChar, this._HBQuaTrinhBenhLy);
            db.AddInParameter(cmd, "@HBTienSuBenhBanThan", SqlDbType.NVarChar, this._HBTienSuBenhBanThan);
            db.AddInParameter(cmd, "@HBDiUng", SqlDbType.Bit, this._HBDiUng);
            db.AddInParameter(cmd, "@HBMaTuy", SqlDbType.Bit, this._HBMaTuy);
            db.AddInParameter(cmd, "@HBRuouBia", SqlDbType.Bit, this._HBRuouBia);
            db.AddInParameter(cmd, "@HBThuocLa", SqlDbType.Bit, this._HBThuocLa);
            db.AddInParameter(cmd, "@HBThuocLao", SqlDbType.Bit, this._HBThuocLao);
            db.AddInParameter(cmd, "@HBKhac", SqlDbType.Bit, this._HBKhac);
            db.AddInParameter(cmd, "@HBDiUngTG", SqlDbType.NVarChar, this._HBDiUngTG);
            db.AddInParameter(cmd, "@HBMaTuyTG", SqlDbType.NVarChar, this._HBMaTuyTG);
            db.AddInParameter(cmd, "@HBRuouBiaTG", SqlDbType.NVarChar, this._HBRuouBiaTG);
            db.AddInParameter(cmd, "@HBThuocLaTG", SqlDbType.NVarChar, this._HBThuocLaTG);
            db.AddInParameter(cmd, "@HBThuocLaoTG", SqlDbType.NVarChar, this._HBThuocLaoTG);
            db.AddInParameter(cmd, "@HBKhacTG", SqlDbType.NVarChar, this._HBKhacTG);
            db.AddInParameter(cmd, "@HBTienSuBenhGiaDinh", SqlDbType.NVarChar, this._HBTienSuBenhGiaDinh);
            db.AddInParameter(cmd, "@KBToanThan", SqlDbType.NVarChar, this._KBToanThan);
            db.AddInParameter(cmd, "@KBMach", SqlDbType.Float, this._KBMach);
            db.AddInParameter(cmd, "@KBNhietDo", SqlDbType.Float, this._KBNhietDo);
            db.AddInParameter(cmd, "@KBHuyetAp1", SqlDbType.Float, this._KBHuyetAp1);
            db.AddInParameter(cmd, "@KBHuyetAp2", SqlDbType.Float, this._KBHuyetAp2);
            db.AddInParameter(cmd, "@KBNhipTho", SqlDbType.Float, this._KBNhipTho);
            db.AddInParameter(cmd, "@KBCanNang", SqlDbType.Float, this._KBCanNang);
            db.AddInParameter(cmd, "@KBChieuCao", SqlDbType.Float, this._KBChieuCao);
            db.AddInParameter(cmd, "@KBCacCoQuan", SqlDbType.NVarChar, this._KBCacCoQuan);
            db.AddInParameter(cmd, "@KBCacXetNghiemCLS", SqlDbType.NVarChar, this._KBCacXetNghiemCLS);
            db.AddInParameter(cmd, "@KBTomTatBenhAn", SqlDbType.NVarChar, this._KBTomTatBenhAn);
            db.AddInParameter(cmd, "@CDNgay", SqlDbType.DateTime, this._CDNgay);
            db.AddInParameter(cmd, "@CDBenhChinhID", SqlDbType.Int, this._CDBenhChinhID);
            db.AddInParameter(cmd, "@CDBenhKemTheoIDList", SqlDbType.VarChar, this._CDBenhKemTheoIDList);
            db.AddInParameter(cmd, "@CDBienChungIDList", SqlDbType.VarChar, this._CDBienChungIDList);
            db.AddInParameter(cmd, "@CDPhanBiet", SqlDbType.NVarChar, this._CDPhanBiet);
            db.AddInParameter(cmd, "@KLTienLuong", SqlDbType.NChar, this._KLTienLuong);
            db.AddInParameter(cmd, "@KLHuongDieuTri", SqlDbType.NChar, this._KLHuongDieuTri);
            db.AddInParameter(cmd, "@KLTaiKham", SqlDbType.NVarChar, this._KLTaiKham);
            db.AddInParameter(cmd, "@KLLoiDan", SqlDbType.NVarChar, this._KLLoiDan);
            db.AddInParameter(cmd, "@KLKhoaID", SqlDbType.Int, this._KLKhoaID);
            db.AddInParameter(cmd, "@KLNgayVaoVien", SqlDbType.DateTime, this._KLNgayVaoVien);
            db.AddInParameter(cmd, "@BuongID", SqlDbType.Int, this._BuongID);
            db.AddInParameter(cmd, "@GiuongID", SqlDbType.Int, this._GiuongID);
            db.AddInParameter(cmd, "@UserModify", SqlDbType.Int, this._UserModify);
            db.AddInParameter(cmd, "@Deleted", SqlDbType.Bit, this._Deleted);

            db.AddOutParameter(cmd, "@NewDateModify", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);

            this._DateModify = (DateTime)cmd.Parameters["@NewDateModify"].Value;
        }
        #endregion Update
        //==========================================================================

        #region Delete
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new RootCriteria(_BenhNhanID.Value));
        }

        private void DataPortal_Delete(RootCriteria criteria)
        {
            this.Execute_Delete(criteria);
        }

        protected void Execute_Delete(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BenhNhanBO_DeleteBO");
            db.AddInParameter(cmd, "@DirectDelete", SqlDbType.Bit, criteria.directDelete);
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, criteria.BenhNhanID);
            db.ExecuteNonQuery(cmd);
        }
        #endregion Delete
        //==========================================================================

        #region Internal method
        internal void Insert()
        {
            if (!this.IsDirty) return;
            DataPortal_Insert();
            MarkOld();
        }

        internal void Update()
        {
            if (!this.IsDirty) return;
            DataPortal_Update();
            MarkOld();
        }

        internal void DeleteSelf()
        {
            if (!this.IsDirty) return;
            if (this.IsNew) return;
            DataPortal_Delete(new RootCriteria(_BenhNhanID.Value));
            MarkNew();
        }
        #endregion Internal method
        //==========================================================================
    }
}
